Imports System.Windows.Forms

Public Class dlgdocumentid

    ' Document ID is stored here.
    Dim m_iDocID As Integer = -1

    ' Get document ID.
    Function GetDocumentID() As Integer
        Return m_iDocID
    End Function

    ' Ok button clicked.
    Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click

        ' Get document ID.
        Dim szID As String = txtDocID.Text

        ' Validate.
        Dim bValid As Boolean = False
        Dim iID As Integer = -1
        If (szID <> "") Then
            If (szID.Contains(".") = False And szID.Contains(",") = False) Then
                If (IsNumeric(szID) = True) Then
                    iID = CInt(szID)
                    If (iID > 0) Then
                        bValid = True
                    End If
                End If
            End If
        End If

        ' Show error if needed.
        If (bValid = False) Then

            ' Show message and prevent dialog exit.
            MsgBox("Document ID is not valid.", MsgBoxStyle.Information)
            Exit Sub

        Else

            ' Store ID.
            m_iDocID = iID

        End If

        ' If everything is ok, exit the dialog.
        Me.DialogResult = System.Windows.Forms.DialogResult.OK
        Me.Close()

    End Sub

    ' Cancel button clicked.
    Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click

        ' Set document ID to -1 indicating cancel operation.
        m_iDocID = -1

        ' Close the dialog.
        Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.Close()

    End Sub

End Class
